package com.swz.dcrm.ui.mine;


import android.os.Bundle;

import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.fragment.app.Fragment;

import android.text.InputType;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.swz.dcrm.adpter.GlobalAdapter;
import com.swz.dcrm.model.BaseResponse;
import com.swz.dcrm.model.Edit;
import com.swz.dcrm.model.Input;
import com.swz.dcrm.model.PersonalInfo;
import com.swz.dcrm.ui.base.BaseFragment;
import com.swz.dcrm.R;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.lifecycle.Observer;
import androidx.navigation.fragment.NavHostFragment;

import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.TextView;

import butterknife.BindView;
import butterknife.OnClick;

import com.swz.dcrm.R;
import com.swz.dcrm.ui.viewmodel.CarManagementViewModel;
import com.swz.dcrm.ui.viewmodel.GroupViewModel;
import com.swz.dcrm.ui.viewmodel.MainViewModel;
import com.swz.dcrm.ui.viewmodel.StaffViewModel;

import java.lang.reflect.Type;

import javax.inject.Inject;

import static android.content.Context.INPUT_METHOD_SERVICE;

/**
 * A simple {@link Fragment} subclass.
 */
public class EditInfoFragment extends BaseFragment {

    @BindView(R.id.toolbar_title)
    TextView title;
    @BindView(R.id.toolbar)
    ConstraintLayout toolbar;
    @BindView(R.id.et)
    EditText et;
    @BindView(R.id.tv_right)
    TextView tvRight;

    @Inject
    StaffViewModel staffViewModel;
    @Inject
    MainViewModel mainViewModel;

    @Inject
    GroupViewModel groupViewModel;

    public static EditInfoFragment newInstance() {

        return new EditInfoFragment();
        // Required empty public constructor
    }

    @Override
    public void onLoadRetry() {
        if (!isNetworkConnected(getContext())){
            mHolder.showLoadingStatus(GlobalAdapter.NET_ERROR);
            return;
        }


    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        et.setFocusable(true);
        et.setFocusableInTouchMode(true);
        et.requestFocus();
        mainViewModel.getInput().setValue(new Input(et,0,true));

        onLoadRetry();
    }

    @Override
    public int layoutId() {
        return R.layout.fragment_edit_info;
    }


    @Override
    public boolean initView() {
        getDigger().inject(this);
        toolbar.setBackgroundColor(getResources().getColor(R.color.bg));
        EditInfoFragmentArgs args=EditInfoFragmentArgs.fromBundle(getArguments());
        et.setHint(getString(R.string.edit_info_hint,args.getTitle()));
        tvRight.setText(getString(R.string.edit_info_save));
        title.setText(getString(R.string.edit_info_title,args.getTitle()).trim());
        if(!args.getValue().equals("test")){
            et.setText(args.getValue());
        }

        if(!args.getInputType().equals("test")){
            et.setInputType(Integer.valueOf(args.getInputType()));
        }


        return true;
    }


    @OnClick(R.id.iv_back)
    public void backClick() {
        NavHostFragment.findNavController(this).navigateUp();
    }
    @OnClick(R.id.tv_right)
    public void ok(){
        EditInfoFragmentArgs args=EditInfoFragmentArgs.fromBundle(getArguments());
         mainViewModel.getEdit().setValue(new Edit(args.getTitle(),et.getText().toString()));
        backClick();


    }
}
